package com.qqbot.impl.botapi;

import com.qqbot.impl.exception.code.BaseResponseCode;
import com.qqbot.impl.service.WebApiService;
import com.qqbot.impl.utils.DataResult;
import com.qqbot.impl.vo.req.ApiRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 接口
 */
@RestController
@RequestMapping("/open/api")
public class WebApi {

    @Autowired
    WebApiService webApiService;

    /**
     * 启动接口
     *
     * @param apiRequest
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/start", method = RequestMethod.POST)
    @ResponseBody
    public DataResult start(@RequestBody ApiRequest apiRequest) throws Exception {
        if (ObjectUtils.isEmpty(apiRequest)) {
            return DataResult.fail(BaseResponseCode.PARAM_ERROR.getMsg());
        }
        return webApiService.start(apiRequest);
    }

    /**
     * 停止接口
     *
     * @param apiRequest
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/stop", method = RequestMethod.POST)
    @ResponseBody
    public DataResult stop(@RequestBody ApiRequest apiRequest) throws Exception {
        if (ObjectUtils.isEmpty(apiRequest)) {
            return DataResult.fail(BaseResponseCode.PARAM_ERROR.getMsg());
        }
        return webApiService.stop(apiRequest);
    }

    /**
     * 同步数据接口
     *
     * @param apiRequest
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/refreshData", method = RequestMethod.POST)
    @ResponseBody
    public DataResult refreshData(@RequestBody ApiRequest apiRequest) throws Exception {
        if (ObjectUtils.isEmpty(apiRequest)) {
            return DataResult.fail(BaseResponseCode.PARAM_ERROR.getMsg());
        }
        return webApiService.refreshData(apiRequest);
    }


}
